package com.youbo.ysqd.event;


import com.youbo.ysqd.model.Block;
import com.youbo.ysqd.tools.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;


@Service
public class SearchReceive implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    RedisCache redisCache;

    public static Block block;

    public static String[] usernames;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {//保证只执行一次


            block=redisCache.getCacheObject("ysqd_myuser");

            if(null==block){
                block=initBlcok();
                redisCache.setCacheObject("ysqd_myuser",block);
            }
            usernames=block.getUsername().split(",");

        }
    }



    public static Block initBlcok(){
        Block dbl=new Block();
        dbl.setId("1");
        dbl.setUsername("常昀,操作员1,操作员2,操作员3,操作员4");
        dbl.setPassword("zjs13835792895");


        dbl.setDaymax(1);
        dbl.setPagesize(5);
        dbl.setStarts(0);
        dbl.setKeyWord("");
        return dbl;
    }
}